package com.lagou.controller;

import com.lagou.bean.UploadResult;
import com.lagou.service.FileUploadService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@Controller
@RequestMapping("/pic")
public class UploadController {
    @Autowired
    private FileUploadService fileUploadService;

    @PostMapping("upload")
    @ResponseBody
    public UploadResult upload(@RequestParam("file") MultipartFile multipartFile) {
        return fileUploadService.upload(multipartFile);
    }

    @GetMapping("download")
    @ResponseBody
    public  UploadResult download(String file) {
        return fileUploadService.downloadFile("lagou-java", file);
    }

    @DeleteMapping("delete")
    @ResponseBody
    public UploadResult delete(String file) {
        return fileUploadService.deleteFile("lagou-java", file);
    }
}
